package com.zh.test11Xml;

import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.File;
import java.util.Iterator;
import java.util.List;

public class Test {
    public static void main(String[] args) throws DocumentException {


        SAXReader sr = new SAXReader();
        Document dom = sr.read(new File("src/students.xml"));
        System.out.println(dom);
        Element studentsEle = dom.getRootElement();
        Iterator<Element> it1 = studentsEle.elementIterator();
        while(it1.hasNext()) {
            Element studentEle = it1.next();
            List<Attribute> atts = studentEle.attributes();
            for(Attribute att: atts) {
                System.out.println("该字节点的属性\t" + att.getName() + " : " + att.getValue());
            }
            Iterator<Element> it2 = studentEle.elementIterator();
            while(it2.hasNext()) {
                Element studentEle2 = it2.next();
                System.out.println("节点\t" + studentEle2.getName()+ " : " + studentEle2.getText());
            }
            System.out.println();

        }

    }
}
